package com.wufan.day03;

import java.sql.ResultSet;

/**
 * 递归方法的使用
 * @author SongWufan
 * @date 2021/3/8 21:59
 */
public class RecursionTest {
    public static void main(String[] args) {
        int sum = 0;
        for (int i = 0; i <= 100; i++){
            sum += i;
        }
        System.out.println(sum);
        RecursionTest recursionTest = new RecursionTest();
        int sum1 = recursionTest.getSum(100);
        System.out.println(sum1);
        int sum2 = recursionTest.getSum1(10);
        System.out.println(sum2);

    }
    public int getSum(int n) {
        if (n == 1){
            return 1;
        }
        else {
            return n + getSum(n - 1);
        }
    }

    /**
     * n的阶层
     * @param n
     * @return
     */
    public int getSum1(int n) {
        if (n == 1){
            return 1;
        }
        else {
            return n * getSum1(n - 1);
        }
    }


}
